package com.office.utils;

import com.office.bean.TDepart;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

@Data
@NoArgsConstructor
public  class DepartBeanUtils<T> {
    private long pageIndex;//当前的页面
    private long pagesize;//页面的大小
    private long pagecount;//总页数
    private long totalpage;//总记录条数
    private List<T> recods;//每页数据的集合

    private long pagestart=1;//开始的序号
    private long pageend;//结束序号
    private List<Long> numbers = new ArrayList<Long>();//记录总共的页数

    public DepartBeanUtils(long pageIndex, long pagesize, long totalpage, List<T> recods) {
        this.pageIndex = pageIndex;
        this.pagesize = pagesize;
        this.totalpage = totalpage;
        this.pagecount = ((this.totalpage%this.pagesize)==0?(this.totalpage/this.pagesize):(this.totalpage/this.pagesize+1));
        this.recods = recods;

        if (pagecount<=10){
            this.pagestart=1;
            this.pageend=pagecount;
        }else {
            this.pagestart = pageIndex-4;
            this.pageend = pageIndex+5;
            if (pagestart<1){
                this.pagestart=1;
                this.pageend=10;
            }else if(pageend>pagecount){
                this.pageend=pagecount;
                this.pagestart=pagecount-9;
            }
        }
        for(long i =pagestart;i<=pageend;i++){
            numbers.add(i);
        }
    }

    @Override
    public String toString() {
        return "DepartPageBean{" +
                "pageIndex=" + pageIndex +
                ", pagesize=" + pagesize +
                ", pagecount=" + pagecount +
                ", totalpage=" + totalpage +
                ", recods=" + recods +
                ", pagestart=" + pagestart +
                ", pageend=" + pageend +
                ", numbers=" + numbers +
                '}';
    }
}


